/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geotools.Prototipe;


import com.google.gwt.user.client.ui.MouseWheelListenerCollection;
import com.vividsolutions.jts.geom.Envelope;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.map.MapContext;
import org.geotools.referencing.CRS;
import org.geotools.renderer.GTRenderer;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapPane;
import org.geotools.swing.action.PanAction;
import org.geotools.swing.action.ZoomInAction;
import org.geotools.swing.action.ZoomOutAction;
import org.geotools.swing.event.MapMouseEvent;
import org.geotools.swing.event.MapMouseListener;
import org.geotools.swing.event.MapPaneEvent;
import org.geotools.swing.event.MapPaneListener;
import org.geotools.swing.styling.JSimpleStyleDialog.GeomType;
import org.geotools.swing.tool.PanTool;
import org.geotools.swing.tool.ZoomInTool;
import org.geotools.tutorial.GuideButton;

import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

/**
 *
 * @author oleg
 */
public class Myframe {
    JMapPane mapPane;
    

    public Myframe() {
        try {
            File sourceFile = new File("improvedmap/improved0.04.shp");
            if (sourceFile == null) {
                return;
            }
            FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);
            SimpleFeatureSource featureSource = store.getFeatureSource();
            // Create a map context and add our shapefile to it
            MapContext map = new MapContext();
            Style style = SLD.createSimpleStyle(featureSource.getSchema());
            Layer layer = new FeatureLayer(featureSource, style);
            map.addLayer(layer);
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.setBounds(0, 0, 600, 600);
            frame.setVisible(true);

            GTRenderer renderer = new StreamingRenderer();
            mapPane = new JMapPane(renderer, map);


           
JPanel buttons = new JPanel();
JButton zoomInButton = new JButton(new ZoomInAction(mapPane));
JButton zoomOutButton = new JButton(new ZoomOutAction(mapPane));
JButton panButton = new JButton(new PanAction(mapPane));
CoordinateReferenceSystem decode = CRS.decode("EPSG:32637");
JButton guideButton = new GuideButton(mapPane, featureSource, new org.geotools.geosearch.Guide(featureSource, null, null, 0), null, "Guide", decode, decode);

frame.add(zoomInButton);
frame.add(zoomOutButton);
frame.add(panButton);
buttons.add(zoomInButton);
buttons.add(zoomOutButton);
buttons.add(panButton);
buttons.add(guideButton);
   frame.add(buttons, BorderLayout.NORTH);
            mapPane.addMouseListener(new MyMouseAdapter(mapPane));

            

            
            frame.add(mapPane, BorderLayout.CENTER);
            mapPane.setVisible(true);
            mapPane.setBackground(Color.white);
            frame.repaint();
            mapPane.repaint();

            
        } catch (NoSuchAuthorityCodeException ex) {
            Logger.getLogger(Myframe.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FactoryException ex) {
            Logger.getLogger(Myframe.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Myframe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Myframe m=new Myframe();
    }





}
